<?php
	header("Content-Type:text/html;charset=utf-8");
	include "utils.php";
	$weChat = new WeChat(APPID,APPSECRET);
	/**1.引导页自动跳转到此页面后url里面会携带信息,获取code**/
	echo $_GET["code"];
	$code = $_GET["code"];
	/**2.通过code换取网页授权access_token**/
	//如果网页授权的作用域为snsapi_base，则本步骤中获取到网页授权access_token的同时，也获取到了openid，snsapi_base式的网页授权流程即到此为止。
	$res = $weChat->_getWebAccess($code);
	var_dump($res);
//	echo "<hr />";
//	echo "页面access_token:".$res->access_token;
	$access_token = $res->access_token;
//	echo "<hr />";
//	echo "用户openid:".$res->openid;
	$openid = $res->openid;
	//获取用户信息
	$userInfo = $weChat->_getuserInfo($access_token,$openid);
	var_dump($userInfo);
//	echo $userInfo;
	$res = $userInfo;
	$openid = $res->openid;
	$nickName = $res->nickname;
	$headImg = $res->headimgurl;
	$province = $res->province;
	$city = $res->city;
	//header("Location:http://shuaiphp.com/frontend/index.html");
?>

<html>
	<head>
		<title></title>
		<meta charset="UTF-8"/>
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
	</head>
	<body>
		<script>
			// console.log(sessionStorage.myUrl);
			sessionStorage.openId = "<?php echo $openid?>";
			sessionStorage.nickName = "<?php echo $nickName?>";
			sessionStorage.headImg =" <?php echo $headImg?>";
			sessionStorage.province = "<?php echo $province?>";
			sessionStorage.city = "<?php echo $city?>";
			location.href = sessionStorage.myUrl;
		</script>
	</body>
</html>